<!DOCTYPE HTML>
<html>
<head>
	<title>创建商品</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="static/assets/global/plugins/bootstrap/css/bootstrap.css" />
	<link rel="stylesheet" type="text/css" href="static/assets/global/css/components.css" />
	<link rel="stylesheet" type="text/css" href="static/assets/admin/pages/css/login.css" />
	<script type="text/javascript" src="static/assets/global/plugins/jquery-1.11.0.min.js"></script>
</head>
<body class="login">
	<div class="content">
		<h3 class="form-title">创建商品</h3>
		<div class="form-group">
			 <label class="control-label">商品名</label>
			 <div>
			 	<input class="form-control" type="text" placeholder="商品名" name="itemname" id="itemname" />
			 </div>
		</div>

		<div class="form-group">
			 <label class="control-label">商品描述</label>
			 <div>
			 	<input class="form-control" type="text" placeholder="商品描述" name="description" id="description" />
			 </div>
		</div>

		<div class="form-group">
			 <label class="control-label">价格</label>
			 <div>
			 	<input class="form-control" type="text" placeholder="价格" name="price" id="price" />
			 </div>
		</div>

		<div class="form-group">
			 <label class="control-label">图片</label>
			 <div>
			 	<input class="form-control" type="text" placeholder="图片" name="imgurl" id="imgurl" />
			 </div>
		</div>

		<div class="form-group">
			 <label class="control-label">库存</label>
			 <div>
			 	<input class="form-control" type="text" placeholder="库存" name="stock" id="stock" />
			 </div>
		</div>


		<div class="form-actions">
			<button class="btn blue" id="create" type="submit">提交创建</button>
		</div>
	</div>
</body>
<script type="text/javascript">
	jQuery(document).ready(function(){

		$("#create").on("click",function(){
			var itemname = $("input[name='itemname']").val();
			var description = $("input[name='description']").val();
			var price = $("input[name='price']").val();
			var imgurl = $("input[name='imgurl']").val();
			var stock = $("input[name='stock']").val();

			if(itemname == null ||itemname == ""){
				alert("商品名不能为空");
				return false;
			}
			if(description == null ||description == ""){
				alert("商品描述不能为空");
				return false;
			}
			if(price == null ||price == ""){
				alert("价格不能为空");
				return false;
			}
			if(imgurl == null ||imgurl == ""){
				alert("商品图片不能为空");
				return false;
			}
			if(stock == null ||stock == ""){
				alert("库存不能为空");
				return false;
			}
			console.log(itemname+","+description+","+price+","+imgurl+","+stock);
			$.ajax({type:"POST",
				contentType:"application/x-www-form-urlencoded",
				url:"http://localhost:8081/miaosha/item/create",
				data:{
					"title":itemname,
					"description":description,
					"price":price,
					"stock":stock,
					"imgUrl":imgurl
				},
				xhrFields:{withCredentials: true},
				success:function(data){
					if(data.status == "success"){
						alert("创建商品成功");
						// window.location.href="login.html"
					}else{
						alert("创建商品失败："+data.data.errMsg);
					}
				},
				error:function(data){
					alert("创建商品失败："+data.responseText );
				}
			});
				return false;
		});
	});
</script>
</html>